<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
  <title>Demo</title>
  <style>
    #container {
      position: relative;
      width: 400px;
      height: 300px;
    }
  </style>
</head>
<body>  
  <div id="container"></div>
  
  <script src="https://s2.ssl.qhres.com/!87edaa34/animator-0.3.1.min.js"></script>
  <script src="/js/spritejs.js"></script>

  <script>
    const paper = spritejs.Paper2D('#container')
    const Sprite = spritejs.Sprite
    const birdsRes = 'https://p.ssl.qhimg.com/d/inn/c886d09f/birds.png'

    paper.setResolution(800, 600)

    const box1 = new Sprite()
    box1.attr({
      anchor: [0.5, 0.5],
      pos: [300, 300],
      size: [212, 188],
      border: [10, 'red'],
      borderRadius: 25,
      bgcolor: '#7fc',
      padding: 10
    })

    box1.textures = [{
      src: birdsRes,
      srcRect: [2, 64, 86, 60],
      rect: [64, 64, 86, 60],
      filter: {
        dropShadow: [2, 2, 10, 'black'],
      }    
    },{
      src: birdsRes,
      srcRect: [2, 2, 86, 60],
      rect: [2, 2, 86, 60],
      filter: {
        opacity: 0.5,
      }    
    },{
      src: birdsRes,
      srcRect: [2, 126, 86, 60],
      rect: [126, 126, 86, 60] ,
    }]

    paper.layer().appendChild(box1)

    box1.on('click', evt => {
      console.log(evt.offsetX, evt.offsetY, evt.targetTextures)
    })

    const s1 = new Sprite()
    s1.attr({
      anchor: [0.5, 0.5],
      pos: [100, 100],
      size: [188, 188],
      border: [6, '#77cc33'],
      borderRadius: 5,
      bgcolor: '#fff',
    })

    const s2 = new Sprite()
    s2.attr({
      anchor: [0.5, 0.5],
      pos: [105, 105],
      size: [200, 200],
      border: [6, '#77cc33'],
      borderRadius: 5,
      rotate: 45,
      bgcolor: 'rgba(255, 133, 77, 0.5)',
    })

    paper.layer().group(s1, s2)
      .attr({
        anchor: [0.5, 0.5],
        pos: [600, 400],    
        size: [200, 200],    
      })
  </script>
</body>
</html>
